package test;

import GameLogic.Background;
import GameLogic.EntityCoordinate;
import GameLogic.EntityModel;
import Input.BasicInput;
import NGLR.NGLR;
import Renderer.*;
import org.lwjgl.opengl.Display;

import java.util.ArrayList;

public class NGLR_test {
    public static void main2(String[] aa){
        RendererSettings sett = new RendererSettings();
        sett.WindowXres = 1900;
        sett.WindowYres = 600;
        sett.WindowResizable = true;
        sett.WindowFullscreen = false;
        Renderer ren = new NGLR(sett);
    }

     public static void main(String[] aa){
        EntityModel model = new EntityModel();

        model.frames=6;
        model.texture_path="src/test/Toki2";
        model.texture_coordinates=  new float[] {0.0f, 0.0f,
                                                0.0f, 1.0f,
                                                1.0f, 1.0f,
                                                1.0f, 0.0f};
        model.vertex_colour =      new float[] {0.0f, 0.0f, 0.0f, 1.0f,
                                        0.0f, 0.0f, 0.0f, 1.0f,
                                        0.0f, 0.0f, 0.0f, 1.0f,
                                        0.0f, 0.0f, 0.0f, 1.0f};

        model.vertices =  new float[] {-0.5f, -0.5f,
                                     0.5f, -0.5f,
                                     0.5f, 0.5f,
                                     -0.5f, 0.5f};
         EntityModel elfka = new EntityModel();
         elfka.frames=1;
         elfka.texture_path="res/ELFKA_1_M kopia.png";       //If drivers support GL_ARB_texture_rectangle then this will work (but expect performance impact)
         elfka.texture_coordinates =new float[] {0.0f, 0.0f,
                                                0.0f, 1.0f,
                                                1.0f, 1.0f,
                                                1.0f, 0.0f};
         elfka.vertex_colour = new  float[] {0.0f, 0.0f, 0.0f, 1.0f,
                                        0.0f, 0.0f, 0.0f, 1.0f,
                                        0.0f, 0.0f, 0.0f, 1.0f,
                                        0.0f, 0.0f, 0.0f, 1.0f};
         elfka.vertices   =  new float[] {-0.5f / (0.77f/2.0f), -0.5f,
                                     0.5f, -0.5f,
                                     0.5f/ (0.77f/2.0f), 0.5f,
                                     -0.5f, 0.5f};


        RendererSettings sett = new RendererSettings();
        sett.WindowXres = 1000;
        sett.WindowYres = 600;
        sett.WindowResizable = true;
        sett.WindowFullscreen = false;
        sett.VSync = true;
        sett.WindowTitle = new String("TEST");
        sett.FpsCap = 60;
        Renderer ekran = new NGLR(sett);
         ekran.LoadProjectionSettings(new ProjectionSettings());

        EntityCoordinate coord = new EntityCoordinate(0.0, 0.0,1.0, -90.0f, 1.0f, 1.0f, ekran.LoadObject(model));
        ArrayList<EntityCoordinate> aaa = new ArrayList<EntityCoordinate>();
        aaa.add(coord);
        aaa.add(new EntityCoordinate(-1.0, -1.0,1.0, -90.0f, 1.0f, 1.0f, aaa.get(0).modelID));
        aaa.add(new EntityCoordinate(-1.0, 0.0,0.2, -90.0f, 1.0f, 1.0f, aaa.get(0).modelID));
         aaa.add(new EntityCoordinate(-1.0, 1.0,-1.0, -90.0f, 1.0f, 1.0f, aaa.get(0).modelID));
        BasicInput bi = new BasicInput(); //init input
         aaa.add(new EntityCoordinate(1.0, 0.0, 0.5, -90.0f, 0.8f, 0.8f, ekran.LoadObject(elfka)));
         Background bg = new Background(2.0, -1.0, 1.0 , true, 0.0, 1.0, 3, "src/test/1.png");
         ekran.LoadBackground(bg);
        // Background bg2 = new Background(8.0, -1.0, 1.0,false , 0.0, 1.0, 3, "src/test/2.jpg");
       //  ekran.LoadBackground(bg2) ;
        int a = bi.update();
         double ppos = 0.0;
         double pos=0.0;
        double tmp = 0;
        double tmp2 = 0;
        float tmp3 =0;
        boolean bbb = false;
        int xx = 1;
        long st = System.currentTimeMillis();
        while (!Display.isCloseRequested()) {
            ekran.DrawFrame(aaa, ppos, 0.0);
            a = bi.update();
            switch (a){
                case 1 : tmp = -0.01 ; break;

                case 2 : tmp = 0.01; break;

                case 3 : pos = -0.01; break;
                case 4 : pos = 0.01; break;

                case 5 : bbb = !bbb; ekran.LoadProjectionSettings(new ProjectionSettings());break;

                case 11 : tmp = 0; break;
                case 12 : tmp = 0; break;

                case 13 : pos = 0; break;
                case 14 : pos = 0; break;

                //case 15 : tmp3 = 0;




            }
            ppos += pos;
            //pos +=0.001 ;
           // System.out.println("X: " + aaa.get(0).posX + "  Y: " + aaa.get(0).posY);
            if((tmp>0 && aaa.get(0).posY+tmp<0.6) || (tmp<0 && aaa.get(0).posY+tmp>-1))
            	aaa.get(0).posY+= tmp;  //values are passed as references, so we can apply changes directly
            if((tmp2>0 && aaa.get(0).posX+tmp2<1.8) || (tmp2<0 && aaa.get(0).posX+tmp2>-1.7))
            	aaa.get(0).posX+= tmp2;
            //System.out.println(aaa.get(0).posX+":"+aaa.get(0).posY);
            if (bbb)aaa.get(2).posZ += 0.01;
            if (aaa.get(2).posZ > 1.0) aaa.get(2).posZ = -1.0;
            if((System.currentTimeMillis() - st > 40) && bbb){
                aaa.get(0).animFrame++;
                if(model.frames <= aaa.get(0).animFrame)
                   // xx = -xx;
                	aaa.get(0).animFrame = 0;


                st =  System.currentTimeMillis();



            }
        }



    }
}
